package com.huan.nacos;

import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingFactory;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.listener.Event;
import com.alibaba.nacos.api.naming.listener.EventListener;
import com.alibaba.nacos.api.naming.listener.NamingEvent;

import java.util.concurrent.TimeUnit;

public class Test2 {
    public static void main(String[] args) throws NacosException, InterruptedException {
        NamingService namingService = NamingFactory.createNamingService("localdev:8848");

        namingService.subscribe("app1", new EventListener() {
            @Override
            public void onEvent(Event event) {

                if (event instanceof NamingEvent namingEvent){
                    String serviceName = namingEvent.getServiceName();
                    System.out.println("serviceName = " + serviceName);


                }
            }
        });

        TimeUnit.SECONDS.sleep(10000);
    }
}
